package app.fugema.shop.util;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import app.fugema.shop.R;

public class ListStringAdapter extends BaseAdapter
{

    private String[] contents;
    private Context mContext;

    public ListStringAdapter(Context context)
    {
        this.mContext =context;
    }
    public ListStringAdapter(Context context , String[] contentStrs)
    {
        this.mContext =context;
        this.contents = contentStrs;
    }

    public void setData( String[] contentStrs )
    {
        this.contents = null;
        this.contents = contentStrs;
        notifyDataSetChanged();
    }


    @Override
    public int getCount()
    {
        return contents.length;
    }

    @Override
    public String getItem(int position)
    {
        return contents[position];
    }

    @Override
    public long getItemId(int position)
    {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent)
    {
        ViewHolder viewHolder ;

        if( convertView == null)
        {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.list_text_item, null);

            viewHolder = new ViewHolder();
            viewHolder.itemText = convertView.findViewById(R.id.text1);
            convertView.setTag( viewHolder );
        }
        else
        {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        viewHolder.itemText.setText( getItem(position) );
        return convertView;
    }


    class ViewHolder
    {
        TextView itemText;
    }
}
